export function preLoadImg() {
  return new Promise((resolve, reject) => {
    const requireModule = require.context(
      '../../public/static/img',
      false,
      /.png|.webp|.jpg|.jpeg|.bmp|.gif$/
    )
    if (requireModule.keys().length === 0) reject()
    const imgArr = []
    for (let i = 0; i < requireModule.keys().length; i++) {
      imgArr.push('/static/img/' + requireModule.keys()[i].substring(2))
    }
    let count = 0
    for (const item of imgArr) {
      const img = new Image()
      img.src = item
      img.onload = () => {
        count++
        if (count === imgArr.length) {
          resolve()
        }
      }
    }
  })
}
